﻿
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "wizard.h"
#include "protree.h"
#include <QMenu>
#include <QAction>
#include <QDebug>


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //添加项目树形控件
    proTree = new ProTree(this);
    ui->proLayout->addWidget(proTree);

    //创建文件菜单
    QMenu *menu_file = new QMenu(tr("文件(&F)"));
    //创建项目动作
    QAction *act_creat_pro = new QAction(QIcon(":/icon/createpro.png"),tr("创建项目"),this);
    act_creat_pro->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_N));
    menu_file->addAction(act_creat_pro);
    //打开项目动作
    QAction *act_open_pro = new QAction(QIcon(":/icon/openpro.png"),tr("打开项目"),this);
    act_open_pro->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_O));
    menu_file->addAction(act_open_pro);

    //创建设置菜单
    QMenu *menu_set = new QMenu(tr("设置(&S)"));
    //设置背景音乐动作
    QAction *act_music = new QAction(QIcon(":/icon/music.png"),tr("背景音乐"),this);
    act_music->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_M));
    menu_set->addAction(act_music);

    //添加到菜单栏
    ui->menubar->addMenu(menu_file);
    ui->menubar->addMenu(menu_set);

    //连接信号和槽
    connect(act_creat_pro,&QAction::triggered,this,&MainWindow::slot_creatPro);


}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::slot_creatPro(bool)
{
    qDebug()<<"Creat Project is trigged"<<endl;
    Wizard wizard(this);
    auto *page = wizard.page(0);
    page->setTitle(tr("创建项目"));
    //连接信号，把项目配置传回来
    connect(&wizard,&Wizard::SigProSettings,proTree,&ProTree::addProToTree);

    wizard.show();
    wizard.exec();

    disconnect(&wizard);
}


